package com.example.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.client.UserClient;
import com.example.pojo.Order;
import com.example.pojo.User;
import com.example.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private UserClient userClient;//进行远程调用的类

    @Autowired
    private OrderService orderService;

    @GetMapping("/findPage")
    public Page<Order> findPage(Integer pageIndex){
        Page<Order> page=new Page<>(pageIndex,3);
        Page<Order> page1=orderService.findAll(page);
        for (Order order:page1.getRecords()){
            User user=userClient.findById(order.getUserId());
            order.setUser(user);
        }
        return page1;
    }

//    @RequestMapping("add")
//    public

    @RequestMapping("/del")
    public void del(@PathVariable Long id){
         orderService.del(id);

    }

    @RequestMapping("/add")
    public String add(@RequestBody User user){
        return userClient.add(user);

    }

    @RequestMapping("/update")
    public String update(@RequestBody User user){
        return userClient.update(user);

    }

//    @GetMapping("findById")
//    public User findById(@RequestParam("id") Long id){
//        return userClient.findById(id);
//    }
}
